package com.baiyue.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baiyue.entity.Menu;
import com.baiyue.model.menu.MenuDataRequest;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 *
 * @author 伍波
 * @date 2023-04-17
 */
@Mapper
public interface MenuMapper extends BaseMapper<Menu> {
    /**
     * 根据id查询菜单
     * @param id 菜单ID
     * @return
     */
    @Select({
            "select",
            "*",
            "from menu",
            "where id = #{id,jdbcType=INTEGER}"
    })
    Menu getMenuById(Integer id);


    List<Menu> findByParentIdAndNameLike(MenuDataRequest request);

    @Select({
            "select",
            "*",
            "from menu",
            "where name like CONCAT('%', #{name}, '%')"
    })
    List<Menu> findByNameLike(String name);


    @Select({
            "select",
            "*",
            "from menu",
            "where parent_id = #{parentId}"
    })
    List<Menu> findByParentId(Integer parentId);


    @Select({
            "select",
            "EXISTS",
            "(SELECT 1 FROM menu WHERE id = #{id})",
    })
    boolean existsById(Integer id);
}
